﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;



using Jungle.Code.Utils;
using Jungle.Prodamo.AdvertManager;

namespace Jungle.Prodamo.User.WebControls
{
    public class Rubriks : WebControl
    {
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.AddAttribute("class", "advm_table");
            writer.RenderBeginTag(HtmlTextWriterTag.Table);
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.AddAttribute("class", "advm_td");
            writer.AddAttribute("colspan", "2");
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.Write("Объявления по рубрикам");
            writer.RenderEndTag();
            writer.RenderEndTag();
            
            Rubrik rbs = new Rubrik();
            rbs.ParentId = 0;
            rbs.GetByParentId();

            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.AddAttribute("valign", "top");
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            for (int i = 0; i < rbs.RubrikList.Count; )
            {
                if (i == (rbs.RubrikList.Count / 2))
                {
                    writer.RenderEndTag();
                    writer.AddAttribute("valign", "top");
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                }

                Rubrik rb = rbs.RubrikList[i];
                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                writer.Write("<strong style=\"font-size: 14px; font-weight: bold;\">" + rb.Title + "</strong><br/>");
                rb.ParentId = rb.RubrikId;
                rb.GetByParentId();
                foreach (Rubrik r in rb.RubrikList)
                {
                    writer.Write("&nbsp;&nbsp;&nbsp;");
                    writer.AddAttribute("style", "text-decoration: none; font-size: 14px;");
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + "/ru/adverts.aspx?cmd=Rubr&Id=" + r.RubrikId.ToString());
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write(r.Title);
                    writer.RenderEndTag();
                    writer.Write("<br/>");
                }
                writer.Write("<br/>");

                writer.RenderEndTag();

                i++;
            }
            writer.RenderEndTag();
            writer.RenderEndTag();

            writer.RenderEndTag();            
            base.RenderContents(writer);
        }
    }
}
